﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Xmobile.BO;
using Xmobile.BO.Apps;
namespace Xmobile.UserControls.AppList
{
    public partial class ucAppList : System.Web.UI.UserControl
    {
        int CatID = 0;
        int PageIndex = 1;
        int PageSize = 14;
        string cat_name = "", cat_url = "", display="style='display:block'";
        public string Display
        {
            get { return display; }
            set { display = value; }
        }
        public int Cat_ID
        {
            get { return CatID; }
            set { CatID = value; }
        }

        public string Cat_Name
        {
            get { return cat_name; }
            set { cat_name = value; }
        }

        public string Cat_Url
        {
            get { return cat_url; }
            set { cat_url = value; }
        }
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["cat_id"] != null && Request.QueryString["cat_id"].ToString() != "")
            {
                CatID = Convert.ToInt32(Request.QueryString["cat_id"]);
            }
            else
            {
                if (CatID == 0)
                {
                    Response.Redirect("/");
                }
            }

            if (Request.QueryString["pageindex"] != null && Request.QueryString["pageindex"].ToString() != "")
            {
                PageIndex = Convert.ToInt32(Request.QueryString["pageindex"]);
            }

            if (Request.QueryString["pagesize"] != null && Request.QueryString["pagesize"].ToString() != "")
            {
                PageSize = Convert.ToInt32(Request.QueryString["pagesize"]);
            }
 
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            DataTable dt = new DataTable();
            dt = AppsBO.Apps_Select_List_Padding(CatID, PageIndex, PageSize);
            repList.DataSource = dt;
            repList.DataBind();
            
            DataTable dtCat = new DataTable();
            dtCat = Xmobile.BO.Category.CategoryBO.Category_Select_by_CatID(CatID);
            if (dtCat != null && dtCat.Rows.Count > 0)
            {
                cat_name = dtCat.Rows[0]["Cat_Name"].ToString();
            }
            
        }
    }
}